﻿namespace Patterns4Net.Core.AttributesPatterns
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.Composition;
    using System.Diagnostics.Contracts;

    [MetadataAttribute]
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public sealed class PatternCreatorExportAttribute : ExportAttribute
    {
        public PatternCreatorExportAttribute(Type attributeType)
            : base(typeof(ICreatePatternFromAttribute))
        {
            this.AttributeType = attributeType;
        }

        public PatternCreatorExportAttribute(IDictionary<string, object> data)
            : base(typeof(ICreatePatternFromAttribute))
        {
            Contract.Requires(data.ContainsKey("AttributeType"));
            Contract.Requires(data["AttributeType"] is Type);
            Contract.Ensures((Type)data["AttributeType"] == this.AttributeType);
            this.AttributeType = (Type)data["AttributeType"];
        }

        public Type AttributeType { get; private set; }
    }
}
